import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_page/cartoon_business/widget/acg_expand_text.dart';
import 'package:xvideos/hj_page/cartoon_business/widget/acg_source_manager.dart';
import 'package:xvideos/hj_page/home_business/tag/carrtoon_tag_page.dart';
import 'package:xvideos/hj_utils/screen.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';

import '../../hj_model/cartoon_media_info.dart';
import '../../hj_model/video_model.dart';
import '../darkweb/widget/shrink_wrap.dart';

class NovelHeader extends StatefulWidget {
  final ACGSourceManager? manager;
  const NovelHeader({super.key, this.manager});

  @override
  State<NovelHeader> createState() => _NovelHeaderState();
}

class _NovelHeaderState extends State<NovelHeader> {
  CartoonMediaInfo? get info => widget.manager?.mediaInfo;

  @override
  Widget build(BuildContext context) {
    return _buildHeader();
  }

  _buildHeader() {
    return Stack(
      children: [
        Positioned(
          left: 0,
          top: 0,
          right: 0,
          child: NetworkImageLoader(
            imageUrl: info?.coverH ?? '',
          ),
        ),
        Positioned.fill(
            child: Container(
          color: Colors.black.withOpacity(.7),
        )),
        Padding(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              (screen.paddingTop + 72).sizeBoxH,
              Row(
                children: [
                  Stack(
                    children: [
                      NetworkImageLoader(
                        imageUrl: info?.coverH ?? '',
                        width: 111,
                        height: 148,
                      ),
                      if (info?.isAudiobooks == true)
                        Positioned(
                          top: 6,
                          left: 6,
                          child: Image.asset('noval_sign.png'.acgImgPath, width: 20),
                        )
                    ],
                  ),
                  12.sizeBoxW,
                  Expanded(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        info?.title ?? '',
                        style: textStyle(16, Colors.white, FontWeight.w500),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                      ),
                      6.sizeBoxH,
                      Row(
                        children: [
                          Text(
                            '共${info?.totalEpisode ?? 0}${info?.unit}',
                            style: textStyle(12, Color(0xff999999), FontWeight.w400),
                          ),
                          8.sizeBoxW,
                          Text(
                            '/',
                            style: textStyle(12, Color(0xff999999), FontWeight.w400),
                          ),
                          8.sizeBoxW,
                          Text(
                            '${info?.getUpdateString ?? ''}',
                            style: textStyle(12, info!.getDetailUpdateColor, FontWeight.w400),
                          ),
                        ],
                      ),
                      if (info?.tagDetails != null && info?.tagDetails?.isNotEmpty == true) ...[
                        6.sizeBoxH,
                        ShrinkWrap(
                          spacing: 10,
                          runSpacing: 10,
                          maxLines: 1,
                          children: List.generate(info!.tagDetails!.length, (index) {
                            TagsBean? tag = info!.tagDetails![index];
                            return InkWell(
                              onTap: () {
                                Get.to(CartoonTagPage(
                                  title: tag.name ?? '',
                                  sId: tag.id ?? '',
                                ));
                              },
                              child: Container(
                                padding: EdgeInsets.symmetric(vertical: 6, horizontal: 12),
                                decoration: BoxDecoration(
                                  color: Color(0xff22252D),
                                  borderRadius: BorderRadius.circular(4),
                                ),
                                child: Text(
                                  '#${tag.name ?? ''}',
                                  maxLines: 1,
                                  style: TextStyle(
                                    color: Color(0xFF999999),
                                    fontSize: 12,
                                  ),
                                ),
                              ),
                            );
                          }),
                        ),
                      ],
                    ],
                  )),
                ],
              ),
              18.sizeBoxH,
              if (info?.summary?.isNotEmpty == true) ...[
                12.sizeBoxH,
                AcgShowMoreTextWidget(
                  summary: info?.summary ?? '',
                  maxWidth: Get.width - 32,
                ),
              ],
              20.sizeBoxH,
            ],
          ),
        ),
      ],
    );
  }
}
